package com.xiaochong.tir.trades.scheduled;

import com.xc.logclient.utils.LogTrace;
import com.xiaochong.tir.trades.config.ExecutorConfig;
import com.xiaochong.tir.trades.service.SelectCoinQuantizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * Created by org on 2018/6/29.
 */
@EnableScheduling
@Component
public class SelectCoinQuantizationScheduled {

    @Autowired
    private SelectCoinQuantizationService selectCoinQuantizationService;
    /**
     * 计算30天创价格新高活新低，项目启动初始化一次放入redis中
     */
    @Async(ExecutorConfig.SCHEDULER_EXECUTOR_POOL)
    @Scheduled(fixedRate = 1000*60*60*365)
    public void calculateNewHighAndLowInit(){
        LogTrace.beginTrace();
        long start = System.currentTimeMillis();
        LogTrace.info("计算30天创价格新高活新低Init","start",String.valueOf(start));
        selectCoinQuantizationService.getHighOrLowCalculate();
        LogTrace.info("计算30天创价格新高活新低Init","end",String.valueOf(System.currentTimeMillis()-start));
    }
    /**
     * 计算30天创价格新高活新低，每天0点2分执行
     */
    @Async(ExecutorConfig.SCHEDULER_EXECUTOR_POOL)
    @Scheduled(cron="0 0/5 0 * * ?")
    public void calculateNewHighAndLow() {
        LogTrace.beginTrace();
        long start = System.currentTimeMillis();
        LogTrace.info("计算30天创价格新高活新低","start",String.valueOf(start));
        selectCoinQuantizationService.getHighOrLowCalculate();
        LogTrace.info("计算30天创价格新高活新低","end",String.valueOf(System.currentTimeMillis()-start));
    }
    /**
     * 计算连续上涨突破，初始化数据
     */
    @Async(ExecutorConfig.SCHEDULER_EXECUTOR_POOL)
    @Scheduled(fixedRate = 1000*60*60*365)
    public void calculateUpLineAndChangeInit(){
        LogTrace.beginTrace();
        long start = System.currentTimeMillis();
        LogTrace.info("计算连续上涨突破Init","start",String.valueOf(start));
        selectCoinQuantizationService.calculateUpLineAndChange();
        LogTrace.info("计算连续上涨突破Init","end",String.valueOf(System.currentTimeMillis()-start));
    }
    /**
     * 计算连续上涨突破，每天0点和12点每5分钟一次
     */
    @Async(ExecutorConfig.SCHEDULER_EXECUTOR_POOL)
    @Scheduled(cron="0 0/5 0,12 * * ?")
    public void calculateUpLineAndChange() {
        LogTrace.beginTrace();
        long start = System.currentTimeMillis();
        LogTrace.info("计算连续上涨突破","start",String.valueOf(start));
        selectCoinQuantizationService.calculateUpLineAndChange();
        LogTrace.info("计算连续上涨突破","end",String.valueOf(System.currentTimeMillis()-start));
    }

    /**
     * 看涨-均线突破，一分钟一次
     */
    @Async(ExecutorConfig.SCHEDULER_EXECUTOR_POOL)
    @Scheduled(fixedRate = 1000*60)
    public void calculateAverageBreak(){
        LogTrace.beginTrace();
        long start = System.currentTimeMillis();
        LogTrace.info("看涨-均线突破","start",String.valueOf(start));
        selectCoinQuantizationService.calculateAverageBreak();
        LogTrace.info("看涨-均线突破","end",String.valueOf(System.currentTimeMillis()-start));
    }

    /**
     * 看涨-上涨突破箱体,下跌突破箱体，一分钟一次
     */
    @Async(ExecutorConfig.SCHEDULER_EXECUTOR_POOL)
    @Scheduled(fixedRate = 1000*60)
    public void calculateBreakBottom(){
        LogTrace.beginTrace();
        long start = System.currentTimeMillis();
        LogTrace.info("看涨-上涨突破箱体","start",String.valueOf(start));
        selectCoinQuantizationService.calculateBreakBottom();
        LogTrace.info("看涨-上涨突破箱体","end",String.valueOf(System.currentTimeMillis()-start));
    }
}
